import Vue from 'vue'
import Layout from '@/layout/NewLayout'

const _import = (file) => require('@/views/' + file).default
const _import_with_name = (file, name) => {
  const component = _import(file)
  return Vue.extend({ ...component, name })
}

/**
 * router自定义配置项
 * hidden: true                   如果设置true则左侧路由菜单隐藏
 * name:'router-name'             <keep-alive>使用必须设置 (must set!!!)
 * meta : {
    role: true                   设置是否有权限
    title: 'title'                当前路由的中文名称
    noCache: true                 如果fasle，页面将不会被缓存(默认为false)
    icon: 'icon-file-text'        当前菜单的图标样式，使用阿里iconfont
  }
 **/

/*
 * 基础路映射
 */
const _401 = _import('errorPage/401')
const _403 = _import('errorPage/403')
const _404 = _import('errorPage/404')
const _500 = _import('errorPage/500')
const _login = _import('login')
const _lock = _import('lock')

/*
 * 业务页面
 */

// gateways
const _gateways = _import_with_name('gateways', 'gateways')

// apps
const _apps = _import_with_name('apps', 'apps')

// clients
const _clients = _import_with_name('clients', 'clients')

// system
const _userManager = _import_with_name('system/user', 'userManager')
const _userSetting = _import_with_name('system/setting', 'userSetting')

export const constantRouterMap = [

  { path: '/login', component: _login, hidden: true },

  // 锁屏
  { path: '/lock', component: _lock, hidden: true },

];

export const asyncRouterMap = [
  {
    path: '/',
    component: Layout,
    hidden: true,
  },
  {
    path: '/gateways',
    component: Layout,
    name: 'gateways',
    meta: { title: 'gateways', icon: 'nav', roles: ['user', 'admin'] },
    children: [
      { path: 'list', name: 'gateway-list', component: _gateways, meta: { title: 'list', icon: 'tab' } },
    ]
  },

  {
    path: '/apps',
    component: Layout,
    name: 'apps',
    meta: { title: 'apps', icon: 'nav', roles: ['user', 'admin'] },
    children: [
      { path: 'list', name: 'apps-list', component: _apps, meta: { title: 'list', icon: 'tab' } },
    ]
  },

  {
    path: '/clients',
    component: Layout,
    name: 'clients',
    meta: { title: 'clients', icon: 'nav', roles: ['user', 'admin'] },
    children: [
      { path: 'list', name: 'clients-list', component: _clients, meta: { title: 'list', icon: 'tab' } },
    ]
  },

  {
    path: '/system',
    component: Layout,
    name: 'system',
    meta: { title: 'system', icon: 'star' },
    children: [
      { path: 'userManager', name: 'userManager', component: _userManager, meta: { title: 'userManager', icon: 'tab', roles: ['admin'] } },
      { path: 'userSetting', name: 'userSetting', component: _userSetting, meta: { title: 'userSetting', icon: 'tab' }, hidden: true },
    ]
  },

  // 错误页面
  {
    path: '/',
    component: Layout,
    name: 'errorpage',
    hidden: true,
    meta: { title: 'errorpage', icon: '404' },
    redirect: 'noRedirect',// 表示面包屑不需要重定向
    children: [
      { path: '401', component: _401, meta: { title: 'page401' } },
      { path: '403', component: _403, meta: { title: 'page403' } },
      { path: '404', component: _404, meta: { title: 'page404' } },
      { path: '500', component: _500, meta: { title: 'page500' } },
    ]
  },

  { path: '*', redirect: '/404' }
];
